package com.nuc.thread.countdownlatch;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.CountDownLatch;

/**
 * @author 诗酒趁年华
 * @version 1.0.0
 * @Description
 * @createTime 2021年08月15日 16:46:00
 */
@Slf4j
public class TestCountDownLatch1 {
    public static void main(String[] args) throws InterruptedException {
        CountDownLatch countDownLatch = new CountDownLatch(3);
        new Thread(()->{
            log.debug("running...");
            try {
                Thread.sleep(1000);
                countDownLatch.countDown();
                log.debug("end run");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        },"t1").start();
        new Thread(()->{
            log.debug("running...");
            try {
                Thread.sleep(1000);
                countDownLatch.countDown();
                log.debug("end run");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        },"t2").start();
        new Thread(()->{
            log.debug("running...");
            try {
                Thread.sleep(1000);
                countDownLatch.countDown();
                log.debug("end run");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        },"t3").start();

        log.debug("waiting");
        countDownLatch.await();
        log.debug("wait end");
    }
}
